package cn.com.shopec.erp.system.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

/**
 * 
 * @ClassName Access
 * @Description 权限表实体
 * @author chengui
 * @date 2013-5-29 下午5:03:55
 */
@Entity
@Table(name = "tbl_scm_access")
public class Access implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1885748953954944192L;
	
	/** 主键. */
	private String id;
	/** 权限名称. */
	private String accessName;
	/** 权限类型:1-菜单，2-页面元素. */
	private int accessType;
	/** 是否直接放行:1-需要授权，2-直接放行. */
	private int needsAuthorization = 1;
	/** 删除标识:0-已删除，1-未删除. */
	private int deleteFlag = 1;
	
	/** 菜单. */
	private Menu menu;
	/** 页面元素. */
	private PageElement pageElement;
	
	/** 角色. */
	private Set<Role> roles = new HashSet<Role>();

	public Access() {
		super();
	}
	public Access(String id) {
		super();
		this.id = id;
	}
	public Access(String id, String accessName, int accessType,
			int needsAuthorization, int deleteFlag, Menu menu,
			PageElement pageElement, Set<Role> roles) {
		super();
		this.id = id;
		this.accessName = accessName;
		this.accessType = accessType;
		this.needsAuthorization = needsAuthorization;
		this.deleteFlag = deleteFlag;
		this.menu = menu;
		this.pageElement = pageElement;
		this.roles = roles;
	}
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	@Column(name = "access_name")
	public String getAccessName() {
		return accessName;
	}
	public void setAccessName(String accessName) {
		this.accessName = accessName;
	}
	@Column(name = "access_type")
	public int getAccessType() {
		return accessType;
	}
	public void setAccessType(int accessType) {
		this.accessType = accessType;
	}
	@Column(name = "needs_authorization")
	public int getNeedsAuthorization() {
		return needsAuthorization;
	}
	public void setNeedsAuthorization(int needsAuthorization) {
		this.needsAuthorization = needsAuthorization;
	}
	@Column(name = "delete_flag")
	public int getDeleteFlag() {
		return deleteFlag;
	}
	public void setDeleteFlag(int deleteFlag) {
		this.deleteFlag = deleteFlag;
	}
	
	@OneToOne(mappedBy = "access")
	public Menu getMenu() {
		return menu;
	}
	public void setMenu(Menu menu) {
		this.menu = menu;
	}
	@OneToOne(mappedBy = "access", fetch = FetchType.LAZY)
	public PageElement getPageElement() {
		return pageElement;
	}
	public void setPageElement(PageElement pageElement) {
		this.pageElement = pageElement;
	}
	
	@ManyToMany(mappedBy = "accesses")
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

}
